using System;
using System.Collections;
using System.Web;
using Sedna.Core.Common;
using Sedna.Core.Controller.Common;

namespace Sedna.Core.Controller.Menu
{
	public class UrlRedirectMenuAwareAction : UrlRedirectAction
	{

		private bool includeInfra = true;
		private bool includeReturnUrl = false;
		private bool returnRedirect = false;

		/// <summary>
		/// to enable automatic generation of infrastructure params such as 
		/// button command name and command argument list
		/// </summary>
		public bool IncludeInfra
		{
			get { return includeInfra; }
			set { includeInfra = value; }
		}

		public bool IncludeReturnUrl
		{
			get { return includeReturnUrl; }
			set { includeReturnUrl = value; }
		}

		public bool ReturnRedirect
		{
			get { return returnRedirect; }
			set { returnRedirect = value; }
		}


		public override IActionResult Execute(IExecutionContext executionContext)
		{
			ArrayList commonParams = new ArrayList(base.ActionParams);
			if(!returnRedirect)
			{
				commonParams.Add(new LeftMenuAwareActionParam());
				commonParams.Add(new TopMenuAwareActionParam());
			}
			if(includeInfra)
			{
				commonParams.AddRange(CommandArgumentParamBuilder.BuildParams(executionContext, null));
			}
			if(includeReturnUrl)
			{
				commonParams.Add(new ReturnUrlActionParam());
			}
			if(returnRedirect)
			{
				Url = (string)executionContext.GetScopedValue(new ReturnUrlActionParam().Name, Scope.Request);
			}
			Execute(executionContext, commonParams);

			return CreateResult(successStatus);
		}
	}
}
